import {Api, MyHttpClient} from "@/api"
import { resolve } from "path";
import { rejects } from "assert";

export default {
    name: "webServer",
    namespaced: true,
    state: {
        status: {
            databaseInitialized: true,
            currentDataBase: {
                database: null,
                driverClass: null,
                initialPoolSize: null,
                jdbcUrl: null,
                maxPoolSize: null,
                minPoolSize: null,
                password: null,
                userName: null,
                metaData: {
                    driverName: null,
                    driverVersion: null,
                    productName: null,
                    productVersion: null
                }
            }
        }
    },
    mutations: {
        setStatus(state, data){
            state.status = data
        }
    },
    actions: {
        getStatus(context){
            return new Promise((resolve, rejects) => {
                new MyHttpClient().get(Api.webServer.webServerStatus()).then(data => {
                    context.commit("setStatus", data.data)
                    resolve(data.data)
                }).catch(exception => {
                    rejects(exception)
                })
            })
        }
    }
}

export const Methods = {
    getStatus(store){
        return store.dispatch("webServer/getStatus")
    }
}
